package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.LiftViolation;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/24
 *
 * 塔吊违章
 */

public class LiftDataViolationListAdapter extends RecyclerAdapter<LiftViolation, LiftDataViolationListAdapter.LiftDataViolationListViewHolder> {

    public LiftDataViolationListAdapter(Context context, List<LiftViolation> dataList) {
        super(context, dataList);
    }

    @Override
    public LiftDataViolationListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_lift_data_list_violation, null);
        return new LiftDataViolationListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(LiftDataViolationListViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class LiftDataViolationListViewHolder extends RecyclerAdapter.BaseViewHolder<LiftViolation>{
        @BindView(R.id.lift_violation_type_tv)
        HXTextView liftViolationTypeTv;
        @BindView(R.id.person_count_tv)
        HXTextView personCountTv;
        @BindView(R.id.lift_tilt_tv)
        HXTextView liftTiltTv;
        @BindView(R.id.lift_driver_tv)
        HXTextView liftDriverTv;
        @BindView(R.id.create_time_tv)
        HXTextView createTimeTv;

        public LiftDataViolationListViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            final LiftViolation liftViolation = dataList.get(position);
            StringBuffer sb = new StringBuffer();
            if(liftViolation.getWarningStatusIdentity() == 0){//报警状态-身份认证 : 0身份认证未正常 1身份认证通过
                sb.append("身份未认证" + "  ");
            }else if(liftViolation.getWarningStatusPersons() == 1){//报警状态-人数 : 0人数正常 1人数超载
                sb.append("超载" + "  ");
            }else if(liftViolation.getWarningStatusHeight() == 1){//报警状态-高度 : 0高度正常 1高度预警 2高度告警
                sb.append("高度预警" + "  ");
            }else if(liftViolation.getWarningStatusHeight() == 2){//报警状态-高度 : 0高度正常 1高度预警 2高度告警
                sb.append("高度报警" + "  ");
            }else if(liftViolation.getWarningStatusSpeed() == 1){//报警状态-速度 : 0速度正常 1速度预警 2速度报警
                sb.append("速度预警" + "  ");
            }else if(liftViolation.getWarningStatusSpeed() == 2){//报警状态-速度 : 0速度正常 1速度预警 2速度报警
                sb.append("速度报警" + "  ");
            }else if(liftViolation.getWarningStatusTilt() == 1){//报警状态-倾斜 : 0 倾斜正常 1倾斜预警 2倾斜报警
                sb.append("倾斜预警" + "  ");
            }else if(liftViolation.getWarningStatusTilt() == 2){//报警状态-倾斜 : 0 倾斜正常 1倾斜预警 2倾斜报警
                sb.append("倾斜报警" + "  ");
            }else if(liftViolation.getWarningStatusWeight() == 1){//报警状态-重量 : 0重量正常 1重量预警 2重量报警
                sb.append("重量预警" + "  ");
            }else if(liftViolation.getWarningStatusWeight() == 2){//报警状态-重量 : 0重量正常 1重量预警 2重量报警
                sb.append("重量报警" + "  ");
            }
            liftViolationTypeTv.setText(sb.toString());
            personCountTv.setText("人数" + liftViolation.getLoadPersons() + "人");
            liftTiltTv.setText("倾斜：" + "（X）" + liftViolation.getMaxXTilt() + "°" + " （Y）" + liftViolation.getMaxYTilt() + "°");
            liftDriverTv.setText("驾驶员：" + liftViolation.getDriverName());
            createTimeTv.setText(liftViolation.getAcquisitionTime());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(liftViolation);
                }
            });
        }
    }
}
